/*     */ package com.zimbra.cs.service.account;
/*     */ 
/*     */ import com.zimbra.common.account.Key.AccountBy;
/*     */ import com.zimbra.common.account.Key.DomainBy;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.AccountConstants;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.common.soap.Element.Disposition;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.StringUtil;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException;
/*     */ import com.zimbra.cs.account.AuthToken;
/*     */ import com.zimbra.cs.account.Domain;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.service.AuthProvider;
/*     */ import com.zimbra.soap.ZimbraSoapContext;
/*     */ import java.util.Map;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class ChangePassword
/*     */   extends AccountDocumentHandler
/*     */ {
/*     */   public Element handle(Element request, Map<String, Object> context)
/*     */     throws ServiceException
/*     */   {
/*  47 */     if (!checkPasswordSecurity(context)) {
/*  48 */       throw ServiceException.INVALID_REQUEST("clear text password is not allowed", null);
/*     */     }
/*  50 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/*  51 */     Provisioning prov = Provisioning.getInstance();
/*     */     
/*  53 */     String namePassedIn = request.getAttribute("account");
/*  54 */     String name = namePassedIn;
/*     */     
/*  56 */     Element virtualHostEl = request.getOptionalElement("virtualHost");
/*  57 */     String virtualHost = virtualHostEl == null ? null : virtualHostEl.getText().toLowerCase();
/*     */     
/*  59 */     if ((virtualHost != null) && (name.indexOf('@') == -1)) {
/*  60 */       Domain d = prov.get(Key.DomainBy.virtualHostname, virtualHost);
/*  61 */       if (d != null) {
/*  62 */         name = name + "@" + d.getName();
/*     */       }
/*     */     }
/*  65 */     Account acct = prov.get(Key.AccountBy.name, name, zsc.getAuthToken());
/*  66 */     if (acct == null) {
/*  67 */       throw AccountServiceException.AuthFailedServiceException.AUTH_FAILED(name, namePassedIn, "account not found");
/*     */     }
/*     */     
/*     */ 
/*     */ 
/*  72 */     if (!Provisioning.onLocalServer(acct)) {
/*     */       try {
/*  74 */         return proxyRequest(request, context, acct.getId());
/*     */       }
/*     */       catch (ServiceException e) {
/*  77 */         if ("service.PROXY_ERROR".equals(e.getCode())) {
/*  78 */           ZimbraLog.account.warn("encountered proxy error", e);
/*     */         }
/*     */         else {
/*  81 */           throw e;
/*     */         }
/*     */       }
/*     */     }
/*     */     
/*  86 */     String oldPassword = request.getAttribute("oldPassword");
/*  87 */     String newPassword = request.getAttribute("password");
/*  88 */     if ((acct.isIsExternalVirtualAccount()) && (StringUtil.isNullOrEmpty(oldPassword)) && (!acct.isVirtualAccountInitialPasswordSet()) && (acct.getId().equals(zsc.getAuthtokenAccountId())))
/*     */     {
/*     */ 
/*  91 */       AuthProvider.validateAuthToken(prov, zsc.getAuthToken(), false);
/*  92 */       prov.setPassword(acct, newPassword, true);
/*  93 */       acct.setVirtualAccountInitialPasswordSet(true);
/*     */     } else {
/*  95 */       prov.changePassword(acct, oldPassword, newPassword);
/*     */     }
/*  97 */     AuthToken at = AuthProvider.getAuthToken(acct);
/*     */     
/*  99 */     Element response = zsc.createElement(AccountConstants.CHANGE_PASSWORD_RESPONSE);
/* 100 */     at.encodeAuthResp(response, false);
/* 101 */     response.addAttribute("lifetime", at.getExpires() - System.currentTimeMillis(), Element.Disposition.CONTENT);
/* 102 */     return response;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public boolean needsAuth(Map<String, Object> context)
/*     */   {
/* 112 */     return false;
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/account/ChangePassword.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */